package multisocket;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class MultiCastReceiver {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		InetAddress group = InetAddress.getByName("224.0.0.1");
		int port = 4000;
		MulticastSocket ms = null;
		ms = new MulticastSocket(port);
		ms.joinGroup(group);
		byte[] buffer = new byte[8192];
		try {
			while (true) {
				DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
				ms.receive(dp);
				String s = new String(dp.getData(), 0, dp.getLength());
				System.out.println(s);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (ms != null) {
				ms.leaveGroup(group);
				ms.close();
			}
		}
	}

}
